const connection = require('../app/database')
class CategoryService {
  async getCateList() {
    const statement = `
      SELECT id,name,pid,level,deleted FROM category;
    `
    const [res] = await connection.execute(statement)
    return res
  }
  async addCate(pid, name, level) {
    const statement = `
      INSERT INTO category (pid,name,level) VALUES (?,?,?);
    `
    const [res] = await connection.execute(statement,[pid,name,level])
    return res
  }
  async getCateById(id) {
    const statement = `
      SELECT id,name,pid,level FROM category WHERE id = ?;
    `
    const [res] = await connection.execute(statement,[id])
    return res
  }
  async updateCateById(name,id) {
    const statement = `
      UPDATE category SET name = ? WHERE id = ?;
    `
    const [res] = await connection.execute(statement, [name, id])
    return res
  }
  async removeCateById(id) {
    const statement = `
      DELETE FROM category WHERE id = ?;
    `
    const [res] = await connection.execute(statement,[id])
    return res
  }
  
}
module.exports = new CategoryService()